package servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.dao.impl.DataDaoImpl;
import org.entity.ConsigneeInfo;
import org.entity.ConsignorInfo;
import org.entity.OrderInfo;
import org.entity.SrCity;
import org.service.IDataService;
import org.service.impl.DataServiceImpl;

/**
 * Servlet implementation class addData
 */
public class addData extends HttpServlet {

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		
		
		DataDaoImpl ddi=new DataDaoImpl();
		
		int consigneeId = ddi.queryOrderId();
		String consigneeName = request.getParameter("consigneeName");
		String phone = request.getParameter("phone");
		String reachAddress = request.getParameter("reachAddress");
		ConsigneeInfo consigneeInfo = new ConsigneeInfo(consigneeId,consigneeName,phone,reachAddress);
		int consignorId =ddi.queryOrderId();
		String consignorName = request.getParameter("consignorName");
		String phone1 = request.getParameter("phone");
		String sendAddress = request.getParameter("sendAddress");
		ConsignorInfo consignorInfo = new ConsignorInfo(consignorId,consignorName,phone,sendAddress);
		int orderId = ddi.queryOrderId();
	    int goodsWT = Integer.parseInt(request.getParameter("goodsWT"));
	    int mailFee = Integer.parseInt(request.getParameter("mailFee"));
	    int consignorId1 = ddi.queryOrderId();
	    int consigneeId1 = ddi.queryOrderId();
	    OrderInfo orderInfo = new OrderInfo(orderId,goodsWT,mailFee,consignorId,consigneeId);
	    int orderId1 = ddi.queryOrderId();
	    String sendCity = request.getParameter("sendCity");
	    String reachCity = request.getParameter("reachCity");
	    SrCity srCity = new SrCity(orderId,sendCity,reachCity);
		IDataService dataService = new DataServiceImpl();
		boolean result = dataService.addData(consigneeInfo, consignorInfo, orderInfo, srCity);
		
		HttpSession session=request.getSession();
		dataService.addMyOrder(orderId,(String)session.getAttribute("username"));
		
		if(result){
			response.sendRedirect("addSuccess.jsp");
		}else{
			System.out.println("增加失败！");
		}
 
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
